import java.util.HashMap;
import java.util.Map;

// 2.计算位置 x 到 y 的最少步数
public class locationX2Y {
    // 缓存已经计算过的状态
    static Map<String, Integer> memo = new HashMap<>();

    public static int solution(int x, int y) {
        int distance = Math.abs(x-y);
        for (int i=1 ; i<=distance ; i++) {
            if ( i*i == distance) {
                return 2*i-1;
            } else if (i*i < distance && i * (i+1) >= distance) {
                return 2*i;
            }
        }
        return distance;
    }

    public static void main(String[] args) {
        // 测试用例
        System.out.println(solution(12, 6) == 4);
        System.out.println(solution(34, 45) == 6);
        System.out.println(solution(50, 30) == 8);
    }
}